fix: add poll_timeout_ms to prevent upload_and_poll() hanging indefinitely (#3097)#3103
fix: add poll_timeout_ms to prevent upload_and_poll() hanging indefinitely (#3097)#3103xodn348 wants to merge 1 commit intoopenai:mainfrom
Conversation
…efinite hang Fixes openai#3097: upload_and_poll() and poll() would hang indefinitely when a vector store file stays stuck in 'in_progress' status. Added poll_timeout_ms parameter (float | None) to: - Files.poll() / AsyncFiles.poll() - Files.create_and_poll() / AsyncFiles.create_and_poll() - Files.upload_and_poll() / AsyncFiles.upload_and_poll() When poll_timeout_ms is set and elapsed time exceeds it, raises TimeoutError with a descriptive message. Uses time.monotonic() for accurate elapsed tracking.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4f14ec39c7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if is_given(poll_timeout_ms) and poll_timeout_ms is not None: | ||
| if (time.monotonic() - start) * 1000 >= poll_timeout_ms: | ||
| raise TimeoutError( | ||
| f"Vector store file {file_id!r} is still in_progress after {poll_timeout_ms:.0f}ms" | ||
| ) |
There was a problem hiding this comment.
Clamp poll sleep to remaining timeout
In Files.poll(), the timeout check runs before self._sleep(...), so when poll_interval_ms (or the openai-poll-after-ms header) is larger than the remaining budget, the call sleeps past the deadline and only raises TimeoutError on the next iteration. That means a configured timeout can be exceeded by a large margin (e.g., 30s timeout with a 60s poll interval), which weakens the behavior this change is meant to guarantee; the async poll path uses the same pattern.
Useful? React with 👍 / 👎.
|
Closing duplicate — #3102 is the canonical PR. |
Summary
Fixes #3097: `vector_stores.files.upload_and_poll()` hangs indefinitely when a vector store file stays stuck at `status="in_progress"`.
Root Cause
The `poll()` method uses an unbounded `while True:` loop with no timeout mechanism. If the OpenAI API gets into a state where a file never leaves `in_progress`, the call will block forever.
Fix
Added an optional `poll_timeout_ms: float | None` parameter to all six polling methods:
When `poll_timeout_ms` is set and the elapsed time (tracked with `time.monotonic()`) exceeds the limit while the file is still `in_progress`, a `TimeoutError` is raised with a descriptive message identifying the stuck file. When not set (default `None`), behavior is unchanged — fully backwards compatible.
Usage
Changes
src/openai/resources/vector_stores/files.py: Addedimport time, addedpoll_timeout_msparameter and timeout check logic to all six polling methods (sync + async)